Passed
Push — main ( 5cacf5...da0f78 )
by Pedro
02:28
created

extend.ts ➔ extend   A

Complexity

Conditions 2

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 16
ccs 7
cts 7
cp 1
rs 9.95
c 0
b 0
f 0
cc 2
crap 2
1
/*
2
 * decimal.js-i18n v0.2.6
3
 * Full internationalization support for decimal.js.
4
 * MIT License
5
 * Copyright (c) 2022 Pedro José Batista <[email protected]>
6
 * https://github.com/pjbatista/decimal.js-i18n
7
 */
8
/* eslint-disable @typescript-eslint/no-unsafe-return */
9
import type Decimal from ".";
10
11
/**
12
 * This function is the only export of this module, and can be used to extend custom builds of `decimal.js`.
13
 *
14
 * @param decimalClass Decimal class/constructor to be extended.
15
 * @returns The augmented class/constructor.
16
 */
17 1
export function extend(decimalClass: Partial<Decimal.Constructor>) {
18 4
    if (!decimalClass || typeof decimalClass.isDecimal !== "function") {
19 1
        throw new TypeError("Invalid argument Decimal argument.");
20
    }
21
22 1
    globalThis.__Decimal__Class__Global__ = decimalClass as Decimal.Constructor;
23 1
    require(".");
24 1
    delete globalThis.__Decimal__Class__Global__;
25 1
    return decimalClass as typeof Decimal;
26
}
27
export default extend;
28